<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
    <title>注册</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="description" content="">
    <link rel="stylesheet" href="${path}/lib/weui.min.css">
    <link rel="stylesheet" href="${path}/css/jquery-weui.css">
    <link rel="stylesheet" href="${path}/css/demos.css">
</head>

<body ontouchstart>

<header class='demos-header'>
    <c:choose>
        <c:when test="${sessionScope.SESSION_USER.status eq 1}">
            <h1 class="demos-title">已注册</h1>
        </c:when>
        <c:otherwise>
            <h1 class="demos-title">注册</h1>
        </c:otherwise>
    </c:choose>
</header>
<div class="weui-cells weui-cells_form">
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">姓名</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" type="text" placeholder="姓名" name="realname" id="realname"
                   value="${sessionScope.SESSION_USER.realname}">
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">手机号</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" id="tel" type="tel" pattern="[0-9]*" placeholder="请输入手机号" name="tel"
                   value="${sessionScope.SESSION_USER.mobile}">
        </div>
    </div>
</div>
<c:if test="${sessionScope.SESSION_USER.status ne 1}">
    <div class="weui-btn-area">
        <a class="weui-btn weui-btn_primary" href="javascript:" id="submit">提交</a>
    </div>
</c:if>

<jsp:include page="foot.jsp"/>
<script src="${path}/lib/jquery-2.1.4.js"></script>
<script src="${path}/lib/fastclick.js"></script>
<script src="${path}/js/jquery-weui.js"></script>

<script>
    $(function () {
        FastClick.attach(document.body);
    });
    $("#submit").click(function () {
        var tel = $('#tel').val();
        var username = $('#realname').val();
        if (!username || username == '') $.toptip('请输入姓名');
        else if (!tel || !/1[3|4|5|7|8]\d{9}/.test(tel)) $.toptip('请输入手机号');
        else {
            var url = '${path}/user/register.do';
            $.post(url, {'realname': username, 'mobile': tel}, function (result) {
                if (result.success) {
                    window.location.href = '${path}/home.do';
                } else {
                    $.toptip(result.message);
                }
            }, 'JSON');
        }
        ;
    });
</script>
</body>
</html>
